import javax.swing.*;
public class LoginView extends JFrame {
    public LoginView() {
        JLabel l_title = new JLabel("登录页面");
        JLabel l_username=new JLabel("用户名");
        JLabel l_password=new JLabel("密码");
        JTextField t_username=new JTextField();
        JTextField t_password=new JPasswordField();
        JButton reset=new JButton("清空");
        JButton login=new JButton("登录");
        JPanel panel=new JPanel();
        JPanel panel1=new JPanel();
        panel1.setVisible(false);
        panel.setLayout(null);
        l_title.setBounds(150, 20, 100, 50);
        l_username.setBounds(100, 80, 100, 20);
        l_password.setBounds(100, 120, 100, 20);
        t_username.setBounds(150, 80, 120, 20);
        t_password.setBounds(150, 120, 120, 20);
        reset.setBounds(130, 160, 60, 20);
        login.setBounds(200, 160, 60, 20);
        reset.addActionListener(e -> {
            t_username.setText("");
            t_password.setText("");
        });
        JLabel success=new JLabel("登录成功");
        success.setBounds(150, 90, 60, 20);
        success.setVisible(false);
        login.addActionListener(e -> {
            if (t_username.getText().equals("admin") && t_password.getText().equals("admin")) {
                JOptionPane.showMessageDialog(null,"登录成功","登录成功",JOptionPane.INFORMATION_MESSAGE);
            }else if (t_username.getText().equals("") && t_password.getText().equals("")) {
                JOptionPane.showMessageDialog(null,"用户名或密码为空","登录失败",JOptionPane.ERROR_MESSAGE);
            }else {
                JOptionPane.showMessageDialog(null,"用户名或密码错误","登录失败",JOptionPane.WARNING_MESSAGE);
            }
        });
        panel.add(success);
        panel.add(l_title);
        panel.add(l_username);
        panel.add(l_password);
        panel.add(t_username);
        panel.add(t_password);
        panel.add(reset);
        panel.add(login);
        this.add(panel);
        this.setTitle("登录页面");
        this.setSize(400,300);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
    public static void main(String[] args) {
        new LoginView();
    }
}
